/*
 * SyncQueue.cpp
 *
 *  Created on: 2015-12-7
 *      Author: Administrator
 */

#include "SyncQueue.h"
SyncQueue::SyncQueue() {
	pthread_mutex_init(&m_mutex, NULL);
}

SyncQueue::~SyncQueue() {
	pthread_mutex_lock(&m_mutex);
	while (!mQueue.empty()) {
		mQueue.pop();
	}
	pthread_mutex_unlock(&m_mutex);
	pthread_mutex_destroy(&m_mutex);
}

void SyncQueue::push(const void* object) {
	pthread_mutex_lock(&m_mutex);
	mQueue.push(object);
	pthread_mutex_unlock(&m_mutex);
}
const void* SyncQueue::pop() {
	const void* object = NULL;
	pthread_mutex_lock(&m_mutex);
	object = mQueue.front();
	mQueue.pop();
	pthread_mutex_unlock(&m_mutex);
	return object;
}
